<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="js/bootstrap.min.js"></script> 
<link rel="stylesheet" href="css/bootstrap.min.css">  
<script type="text/javascript" src="jquery-3.0.0.min.js"></script>
<script type="text/javascript">
$(function(){
	$("#save").click(function(){
		//var loginName=$("loginName").val();
		//var realName=$("realName").val();
		//var password=$("password").val();
		$.ajax({
			url:"/focus/user",
			type:"POST",
			data:{loginName:$("#loginName").val(),realName:$("#realName").val(),password:$("#password").val()},
			success:function(d){
				//alert("ok")
				if(d['status']==500){
					alert(d['data']);
				}
				if(d['status']==200){
					alert("新增成功");
					window.opener.location.href = window.opener.location.href;
					window.close();
				}
			},
			error:function(){},
			dataType:"json"
		});
	});
	
	$("#loginName").blur(function(){
		//alert($("#loginName").val());
		if($("#loginName").val()==""){
			$("#warn").text("请填写用户名");
			$("#save").attr("disabled","true");//禁用按钮
		}else{
			$.ajax({
				url:"/focus/user/isExist",
				type:"GET",
				data:{loginName:$("#loginName").val()},
				success:function(d){
					//alert("ok")
					if(d['status']==500){
						alert(d['data']);
					}
					if(d['status']==200){
						
						if(d['data']==true){
							//alert("ok")
							$("#warn").text("用户名已存在");
							$("#save").attr("disabled","true");
						}else{
							$("#warn").text("用户名可以使用");
							$("#save").attr("disabled",false);
						}
					}
				},
				error:function(){},
				dataType:"json"
			}); 
		}
	});
	
	
});
</script>
</head>
<body>
	<div class="container-fluid">
	<div class="row-fluid">
		<div class="span12">
			<table class="table">
				<thead>
					<tr><td colspan="2">请填写注册用户信息</td></tr>
				</thead>
				<tbody>
					<tr>
						<td>
							用户登陆名：
						</td>
						<td>
							<input type="text" id="loginName" /><span id="warn"></span>
						</td>
					</tr>
					<tr class="success">
						<td>
							用户真实姓名：
						</td>
						<td>
							<input type="text" id="realName"/>
						</td>
					</tr>
					<tr class="error">
						<td>
							密码：
						</td>
						<td>
							<input type="password" id="password"/>
						</td>
					</tr>
					<tr>
						<td colspan="2">
							<button id="save" class="btn btn-primary btn-small" type="button" style="margin-top: 10px">提交</button>
						</td>					
					</tr>
				</tbody>
			</table>
		</div>
	</div>
</div>
</body>
</html>